package com.feiyu.sys.utils

import com.feiyu.sys.web.ResponseVo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * Created by zdy on 2017/11/28.
 */
@Service
class DynamicSqlExecuteUtils {

    public static final int LONG_ONE = 1l
    @Autowired
    SysSql sqlDb

    /**
     * 执行sql语句 获取多行数据
     * @param sql
     * @return
     * @throws Exception
     */
    ResponseVo getMultiColumns(String sql) throws Exception{
        ResponseVo result = new ResponseVo()
        List rows = sqlDb.rows(sql)
        result.data = rows
        result.count = rows.size()
        return result
    }
    /**
     * 执行sql语句 获取一行数据
     * @param sql
     * @return
     * @throws Exception
     */
    ResponseVo getOneColumn(String sql) throws Exception{
        ResponseVo result = new ResponseVo()
        result.count = LONG_ONE
        Object row = sqlDb.firstRow(sql)
        result.data = row
        return result
    }
}
